@extends("index")
@section("content")
<form action="/addclient" method="post" accept-charset="utf-8" class="form-inline">
    <fieldset>
        <h3 class="sub-header">客户信息</h3>
        <div class="form-group">
            <div class="col-lg-10">
                <input type="text" class="form-control" id="name" spellcheck="false" placeholder="姓名">
            </div>
        </div>
        <div class="form-group">
            <div class="col-lg-10">
                <select id="sex" class="form-control">
                    <option value="1">男</option>
                    <option value="2">女</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <div class="col-lg-10">
                <input type="text" class="form-control" id="address" spellcheck="false" placeholder="地址">
            </div>
        </div>
        <div class="form-group">
            <div class="col-lg-10">
                <input type="text" class="form-control" id="phone" spellcheck="false" placeholder="电话">
            </div>
        </div>
        <div class="form-group">
            <div class="col-lg-10">
                <input type="text" class="form-control" id="age" spellcheck="false" placeholder="年龄">
            </div>
        </div>
        <div class="form-group"><input class="btn btn-primary" type="button" value="提交" onclick="addclient()"></div>

        <div class="form-group">
            <div class="col-lg-10">
                <select id="client" class="form-control" onchange="setclient()">
                <option value="0">已存客户</option>
                </select>
            </div>
        </div>
    </fieldset>
</form>
<div id="OrderTable"></div>
@stop
@section('script')
<script type="text/javascript">
$(function () {
    $("#xiaoshou").addClass("active");
    $('.datetimepicker').datetimepicker({
        format: 'yyyy-mm-dd',
        autoclose: true,
        language:  'zh-CN',
        minView: 'month',
    });
    getclients();
});
function addclient(){
    $.ajax({
        url:"/addclient",
        type:"POST",
        async:false,
        data:{
            "姓名":$("#name").val(),
            "性别":$("#sex").val(),
            "地址":$("#address").val(),
            "电话":$("#phone").val(),
            "年龄":$("#age").val()
        },
        success:function(json){
            if(json.Result == "OK"){
            addorder(json.Record.id);
            alert("添加成功");
            // return json.Record.id;
            }
        }
    })
}
function getmaxorderid () {
    $.post('getmaxorderid',{},function(res){
        if(res.Result = "OK"){
        var maxid = res.maxid;
        }
    });
}
function addorder (clientid) {
    $.post("/addorder",{
    "clientid":clientid,
    },function(json){
    if(json.Result == "OK"){
    $('#OrderTable').jtable({
    disabled: true,
    title: '订单信息',
    actions: {
    listAction: '/getselldetail?sellid='+json.Order.id,
    createAction: '/addselldetail?sellid='+json.Order.id,
    updateAction: '/editeselldetail?sellid='+json.Order.id,
    deleteAction: '/deleteselldetail',
    },
    fields: {
    id: {
    key: true,
    list: false
    },
    订单号: {
    title: '订单号',
    list: false,
    create: false,
    edit: false
    },
    车型: {
    title: '车型',
    options: '/getcars'
    },
    数量: {
    title: '数量',
    },
    售价: {
    title: '售价',
    },
    }
    });
    $('#OrderTable').jtable('load');
    }
    })
}

function getclients () {
    $.post("/getclientslist",
        {},function(json) {
            $.each(json.Records,function(id,record){
                // alert(record);
                $("#client").append("<option value='"+record.id+"'>"+record.姓名+"</option>");
            })
        })
}

function setclient(){
    if($("#client").val()!=0){
        clientid = $("#client").val();
        addorder(clientid);
    }
}
</script>
@stop